<template>
	<view class="">

	</view>
</template>

<script setup>
	let arrs = [1, 2, 3, 4,5,6,7];
	let newArrs = [];
	let newArrs1 = [];
	let newArrs2 = [];
	let newArrs3 = [];
	
	arrs.forEach(item => {
		newArrs.push(item * 2);
	});
	console.log("原始循环方法：", newArrs);

	newArrs = arrs.map(item => {
		return item * 2
	});
	console.log("map方法：", newArrs);
	
	newArrs1 = arrs.filter(item => {
		return item > 2
	});
	console.log("filter方法：", newArrs1);
	

	let arrs2 = [{
		name: "华为",
		price: 6999
	}, {
		name: "苹果",
		price: 9888
	}, {
		name: "小米",
		price: 4999
	}]
	newArrs2 = arrs2.map(item => {
		return {
			...item,//将每个元素解开，即可对元素中的属性进行重新定义和增加新元素
			price:item.price + "元",
		}
		// return item.name
	});
	console.log("map方法返回name：", newArrs2);
	
	newArrs3= arrs2.filter(item => {
			return item.price < 5000		
		}
	).map(item=>item.price + 20);
	console.log("filter方法返回price < 5000：", newArrs3);
	
	let newArrs4= arrs.reduce((prev,current)=>{
		return prev + current
	},0);
	console.log("reduce方法求和：", newArrs4);
	
</script>

<style lang="scss" scoped>

</style>